import { Controller } from "egg";

export default class HomeController extends Controller {
  public async index() {
    const { ctx } = this;

    ctx.body = {
      message: "欢迎使用文档协同服务",
      version: "1.0.0",
      timestamp: new Date().toISOString()
    };
  }

  public async health() {
    const { ctx } = this;

    // 记录健康检查请求日志
    ctx.logger.info("[HEALTH] 健康检查请求", {
      requestId: ctx.reqId,
      ip: ctx.ip,
      userAgent: ctx.get("User-Agent"),
      timestamp: new Date().toISOString()
    });

    const healthData = {
      status: "ok",
      message: "服务器运行正常",
      uptime: process.uptime(),
      memory: process.memoryUsage(),
      timestamp: new Date().toISOString()
    };

    ctx.logger.info("[HEALTH] 健康检查响应", {
      requestId: ctx.reqId,
      ip: ctx.ip,
      status: healthData.status,
      uptime: healthData.uptime,
      timestamp: healthData.timestamp
    });

    ctx.body = healthData;
  }
}
